function AllReady() {
	var mstform = Ext.getCmp("KC_OUTCGTH_Head"); //获取容器
	var dgrid = Ext.getCmp("KC_OUTCGTH_Body");
	var Toolbar = Ext.getCmp("toolbar");
	var dstore = dgrid?.store;
	console.log(mstform, "mstform");
	console.log(dgrid, "dstore");

	var PhidTrProj = mstform.queryById("PhidTrProj");
	var PhidWarehouse = mstform.queryById("PhidWarehouse");
	var user_division = mstform.queryById("user_division"); //获取字段
	var user_product_line = mstform.queryById("user_product_line");
	var user_regional_center = mstform.queryById("user_regional_center");
	var user_pro_no = mstform.queryById("user_pro_no");
	var user_ck_address = mstform.queryById("user_ck_address");
	var user_real_amt = mstform.queryById("user_real_amt");
	var PhidContractno = mstform.queryById("PhidContractno");
	var PhidCompno = mstform.queryById("PhidCompno");
	var ContractName = mstform.queryById("ContractName");
	var PhidWarehouse = mstform.queryById("PhidWarehouse");
	var PhidChkpsn = mstform.queryById("PhidChkpsn");
	var PhidChkpsn = mstform.queryById("PhidChkpsn");
    //   var toolbar = Ext.getCmp('toolbar');
    //   toolbar.get('imp').setText('引用采购入库')

	// Toolbar.insert(5, {
	// 	itemId: "cgth",
	// 	text: "发布UIC",
	// 	width: this.itemWidth,
	// 	iconCls: "icon-Copy",
	// 	handler: function () {
	// 		if (ugj == undefined) {
	// 			Ext.MessageBox.alert(Lang.Notes || "提示", "请推送到uic平台!");
	// 			return false;
	// 		} else if (ugj == 1) {
	// 			Ext.MessageBox.alert(Lang.Notes || "提示", "请等待供应商确认!");
	// 			return false;
	// 		} else if (ugj == 2) {
	// 			var paybillUrl =
	// 				location.protocol +
	// 				"//" +
	// 				location.host +
	// 				"/SecondDev/api/Contract/Post";
	// 			Ext.Ajax.request({
	// 				url: paybillUrl,
	// 				type: "POST",
	// 				dataType: "json",
	// 				contentType: "application/json;charset=UTF-8",
	// 				jsonData: {
	// 					billphid: phid,
	// 					jkdm: "pcm3_cnt_m_lwcbfj",
	// 					//                                "jkdm": "pcm3_cnt_m_fwfj"
	// 				},
	// 				success: function (response) {
	// 					window.wait = false;
	// 					//Ext.JSON.decode
	// 					var resdata = JSON.parse(response.text);
	// 					//var resdata = Ext.JSON.decode(response.text);
	// 					var status = resdata["status"];
	// 					var message = resdata["message"];
	// 					if (status == "success") {
	// 						Ext.MessageBox.alert(
	// 							Lang.Notes || "提示",
	// 							"推送成功，请指定盖章位置",
	// 							function () {
	// 								//successCallback(res);
	// 							}
	// 						);
	// 					} else {
	// 						Ext.MessageBox.alert(Lang.Notes || "提示", message, function () {
	// 							//successCallback(res);
	// 						});
	// 					}
	// 				},
	// 				failure: function (response, opts) {
	// 					//myMask.hide();
	// 					window.wait = false;
	// 					var resdata = JSON.parse(response.text);
	// 				},
	// 			});
	// 		}
	// 	},
	// });

    //仓库
    PhidWarehouse.addListener("helpselected", function () {
        execServer(
            "getStoreInfo",
            { store: PhidWarehouse.getValue() },
            function (res) {
                if (res.count > 0) {
                    var obj = JSON.parse(res.data);
                    PhidChkpsn.setValue(obj[0].extendObjects.manapsn)
                    BatchBindCombox([PhidChkpsn])
                }
            }
        );
    });

	PhidTrProj.addListener("helpselected", function () {
		execServer("getProjInfo", { pc: PhidTrProj.getValue() }, function (res) {
            console.log(`项目信息`,res);
			if (res.count > 0) {
				var obj = JSON.parse(res.data);
				const { pc_no, dept, qyzx_name, qyzx, cpx, zz } = obj[0]?.extendObjects;
				console.log(obj, "obj");
				PhidTrProjFun(pc_no, zz, qyzx_name, qyzx, cpx);
			}
		});
	});
	PhidWarehouse.addListener("helpselected", function (arg) {
		user_ck_address?.setValue(arg.data.Addr);
		BatchBindCombox([user_ck_address]);
	});
	console.log(PhidContractno, "PhidContractno");
	mstform.getItem("PhidContractno").addListener("helpselected", function (arg) {
		console.log(arg, "arg");
		// PhidCompno?.setValue(arg.data.PhidSenComp);
		// BatchBindCombox([PhidCompno]);
		// ContractName?.setValue(arg.data.Title);
		// BatchBindCombox([ContractName]);
	});

	dgrid.addListener("edit", function (editor, e) {
		const data = dgrid.getSelectionModel().getSelection(); //获取当前选中行
		if (!data[0]?.data?.user_return_qty && !data[0]?.data?.user_return_prc)
			return;
		const { user_return_qty, user_return_prc, Qty } = data[0]?.data;
		if (Qty < user_return_qty) {
			data[0].set("user_return_qty", Qty);
			Ext.Msg.alert("提示", "退货数量不能大于订单数量");
			return;
		}
		if (
			user_return_qty !== undefined &&
			user_return_prc !== undefined &&
			typeof user_return_qty === "number" &&
			typeof user_return_prc === "number"
		) {
			data[0].set("user_return_amt", user_return_qty * user_return_prc);
		}

		getSum(mstform, dstore);
	});

	if (otype == $Otype.ADD || otype == $Otype.EDIT || otype == $Otype.COPY) {
		dstore.on("datachanged", async function (dstore, eOpts) {
			getSum(mstform, dstore);
		});
	}
	function PhidTrProjFun(pc_no, dept, qyzx_name, qyzx, cpx) {
		user_division?.setValue(dept);
		user_product_line?.setValue(cpx);
		user_regional_center?.setValue(qyzx);
		user_pro_no?.setValue(pc_no);
		BatchBindCombox([user_division]);
		BatchBindCombox([user_product_line]);
		BatchBindCombox([user_regional_center]);
		BatchBindCombox([user_pro_no]);
	}
	function getSum(mstform, dstore) {
		//表体计算 修改后  循环计算前暂停渲染，结束后再开启
		Ext.suspendLayouts();
		var sum = 0;
		for (var i = 0; i < dstore.getCount(); i++) {
			var Qty = dstore.getAt(i).get("Qty");
			var Prc = dstore.getAt(i).get("Prc");
			var tax_price = Qty * Prc; //价税合计
			sum += tax_price;
			user_real_amt.setValue(sum);
		}
		Ext.resumeLayouts();
	}
}
